<?php
/**
 * Created by PhpStorm.
 * User: zty
 * Date: 2018/10/23
 * Time: 21:11
 */

namespace app\web\controller;
use think\App;
use think\Controller;
use think\Request;


class Index extends Controller
{
    private $user_info;
    public function __construct(App $app = null)
    {
        parent::__construct($app);
        $this->user_info = $this->request->userInfo;

    }

    public function index(){
        $user  = $this->user_info;
        $institution = model('common/Institution')->get_one($user['ins_id'],['id','name']);

        $data['name'] = $user['name'];
        $data['duties'] = $institution['name'].$user['duties'];

        $data['time'] = $this->format_time();
        //待处理
        $data['count_1'] = model('common/order')->count_status($user['authority'],$user['ins_id'],1,$this->user_info['id']);
        //处理中
        $data['count_2'] = model('common/order')->count_status($user['authority'],$user['ins_id'],2,$this->user_info['id']);
        //已完成
        $data['count_3'] = model('common/order')->count_status($user['authority'],$user['ins_id'],3,$this->user_info['id']);

        return ['code'=>0,'msg'=>'数据获取成功','data'=>$data];
    }

    private function format_time(){
        $h = date('H',time());
        if($h >= 5 && $h <12 ){
            return '上午好';
        }elseif($h >=12 && $h < 19){
            return '下午好';
        }else{
            return '晚上好';
        }
    }


    public function upload(){
        $time = time();
        $arr = [];
        // 获取表单上传文件
        $files = request()->file('image');
        foreach($files as $file){
            // 移动到框架应用根目录/uploads/ 目录下
            $info = $file->validate(['size'=>156780000000,'ext'=>'jpg,png,gif'])->move( './uploads');
            if($info){
                // 成功上传后 获取上传信息
                // 输出 jpg
//                echo $info->getExtension();
//                // 输出 20160820/42a79759f284b767dfcb2a0197904287.jpg
//                echo $info->getSaveName();
//                // 输出 42a79759f284b767dfcb2a0197904287.jpg
//                echo $info->getFilename();
                // 上传失败获取错误信息
                //echo $file->getError();
                $arr[] = '/uploads/'.date('Ymd',$time).'/'.$info->getFilename();

            }else{
                return ['code'=>1,'msg'=>$file->getError()];
            }
        }
        return ['code'=>0,'msg'=>'上传成功','src'=>$arr];
    }

}